<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>

<c:if test="${userID==null}">
  <c:redirect url="index-msa.jsp" />
</c:if>

<c:if test="${userType!='A'}">
  <c:redirect url="main.jsp" />
</c:if>

<c:if test="${param.mode=='del'}">
  <sql:transaction dataSource="${dataSource}">
    <sql:update>
      delete from t_forums where c_code = ? 
    <sql:param value="${param.target}" />
    </sql:update>

    <sql:update>
      delete from t_messages where c_forum_code = ? 
    <sql:param value="${param.target}" />
    </sql:update>
    
  </sql:transaction>

  <h3>Forum deleted</h3>
</c:if>

<html>
  <head>
    <title>Admin</title>
  </head>

  <body link="#000000" vlink="#000000" alink="#000000">
  <sql:query var="forums" dataSource="${dataSource}">select
  c_code,c_name from t_forums order by c_sequence</sql:query>

  <p>From this screen you can edit forums, delete forums or create
  new forums. 
  <br />

  You may also edit users.</p>

  <table border="0" width="393">
    <tbody>
      <tr>
        <td colspan="3" bgcolor="#0000FF" width="381">
          <b>
            <font size="4" color="#FFFFFF">The following forums are
            available:</font>
          </b>
        </td>
      </tr>

      <c:forEach var="row" items="${forums.rows}"
      varStatus="status">
        <jsp:useBean id="status"
        type="javax.servlet.jsp.jstl.core.LoopTagStatus" />

        <c:choose>
          <c:when test="<%=status.getCount()%2==0%>">
            <c:set var="color" value="#FFFFFF" />
          </c:when>

          <c:otherwise>
            <c:set var="color" value="#FFFF66" />
          </c:otherwise>
        </c:choose>

        <c:url value="${pageContext.request.requestURI}" var="del">
          <c:param name="mode" value="del" />

          <c:param name="target" value="${row.c_code}" />
        </c:url>

        <c:url value="editforum.jsp" var="edit">
          <c:param name="mode" value="edit" />

          <c:param name="target" value="${row.c_code}" />
        </c:url>

        <tr bgcolor="<c:out value="${color}"/>">
        <td width="192">
          <a href="<c:out value="${del}"/>">[Delete]</a>

          <a href="<c:out value="${edit}"/>">[Edit]</a>
        </td>

        <td width="22">
          <c:out value="${row.c_code}" />
        </td>

        <td width="165">
          <c:out value="${row.c_name}" />
        </td>
        </tr>
      </c:forEach>
    </tbody>
  </table>

  &#160;
  <p>
    <a href="newforum.jsp">[New Forum]</a>

    <a href="users.jsp">[Edit Users]</a>

    <a href="main.jsp">[Exit]</a>
  </p>
  </body>
</html>